# == Coding: UTF-8 ==
# @Project :        BooksManagementSystem
# @fileName         main.py  
# @version          v0.5
# @author           Echo
# @GiteeWarehouse   https://gitee.com/liu-long068/
# @editsession      2023/3/30
# @Software:        PyCharm
# ====/******/=====
# == Coding: UTF-8 ==
# @Project :        DormitoryManagementSystem
# @fileName         run_login.py
# @version          v0.5
# @author           Echo
# @GiteeWarehouse   https://gitee.com/liu-long068/
# @editsession      2023/6/1
# @Software:        PyCharm
# ====/******/=====
import sys

from public.menus.menu import Menu
from public.utils.forget_password import ForgetPassword
from public.utils.login import Login
from public.utils.register import Register
from public.utils.stu_login import StudentLogin
from public.AdministratorOperationFunction.admin_function import AdministratorOperationFunction


def normal_exit():
    print("退出成功！欢迎再次使用！")
    sys.exit()


def handle_invalid_choice():
    print("无效操作！请重新输入")


def main():
    menu = Menu()
    login = Login()
    register = Register()
    fp = ForgetPassword()
    admin_f = AdministratorOperationFunction()
    sso_options_menu = {
        '1': {
            '1': login.login_business,
            '2': register.register_business,
            '3': {
                '1': fp.reset_password,
                '0': menu.home_menu
            },
            '0': normal_exit
        },
        '2': {
            '1': admin_f.inputs_student_information,
            '2': admin_f.query_student_borrow_information,
            '3': admin_f.query_Alldisable_student_information,
            '4': admin_f.query_Allblacklist_student_information,
            '5': admin_f.add_blacklist,
            '6': admin_f.disable_student_borrow_permission,
            '7': admin_f.remove_student_disable_permission,
            '0': normal_exit
        },
        '0': normal_exit
    }
    while True:
        menu.SSO_menu()
        choice = input("请操作：")
        # 操作逻辑
        if choice in sso_options_menu:
            option = sso_options_menu[choice]
            if callable(option):
                option()
            elif isinstance(option, dict):
                while True:
                    option_menu = option
                    menu.home_menu()
                    sub_choice = input("请操作：")
                    if sub_choice in option:
                        sub_option = option[sub_choice]
                        if callable(sub_option):
                            sub_option()
                        elif isinstance(sub_option, dict):
                            continue
                        else:
                            handle_invalid_choice()
                    elif sub_choice == '0':
                        break
                    else:
                        handle_invalid_choice()
            else:
                handle_invalid_choice()
        else:
            handle_invalid_choice()


if __name__ == '__main__':
    main()
